JBoss Community Archive (Read Only)

Teiid 8.3

Extending the ExecutionFactory Class

The main class in the translator implementation is ExecutionFactory. A base class is provided in the Teiid API, so a custom translator must extend org.teiid.translator.ExecutionFactory to connect and query an enterprise data source. This extended class must provide a no-arg constructor that can be constructed using Java reflection libraries. This Execution Factory need define/override following elements.

package org.teiid.translator.custom;

@Translator(name="custom", description="Connect to My EIS")
public class CustomExecutionFactory extends ExecutionFactory<MyConnectionFactory, MyConnection> {

    public CustomExecutionFactory() {
    }
}                

Define the annotation @Translator on extended "ExecutionFactory" class. This annotation defines name and description of your translator, and also used as identifier during the deployment. This is name you would be using in the VDB and else where in the configuration to refer to this translator.

ConnectionFactory

Defines the "ConnectionFactory" interface that is defined in resource adapter. This defined as part of class definition of extended "ExecutionFactory" class. Refer to "MyConnectionFactory" sample in the previous chapter.

Connection

Defines the "Connection" interface that is defined in resource adapter. This defined as part of class definition of extended "ExecutionFactory" class. Refer to "MyConnection" class sample in the previous chapter.

Configuration Properties

If the translator requires external configuration, that defines ways for the user to alter the behavior of a program, then define a attribute variable in the class and define "get" and "set" methods for that attribute. Also, annotate each "get" method with @TranslatorProperty annotation and provide the metadata about the property.

For example, if you need a property called "foo", by providing the annotation on these properties, the Teiid tooling can automatically interrogate and provide graphical way to configure your Translator while designing your VDB.

private String foo = "blah";
@TranslatorProperty(display="Foo property", description="description about Foo") 
public String getFoo() 
{
   return foo;
}

public void setFoo(String value) 
{
   return this.foo = value;
} 

Only java primitive (int, boolean), primitive object wrapper (java.lang.Integer), or Enum types are supported as Translator properties. Complex objects are not supported. The default value will be derived from calling the getter method, if available, on a newly constructed instance. All properties should have a default value. If there is no applicable default, then the property should be marked in the annotation as required. Initialization will fail if a required property value is not provided.

The @TranslatorProperty defines the following metadata that you can define about your property

  • display: Display name of the property

  • description: Description about the property

  • required: The property is a required property

  • advanced: This is advanced property; A default value must be provided. A property can not be "advanced" and "required" at same time.

  • masked: The tools need to mask the property; Do not show in plain text; used for passwords

Initializing the Translator

Override and implement the start method (be sure to call "super.start()") if your translator needs to do any initializing before it is used by the Teiid engine. This method will be called by Teiid, once after all the configuration properties set above are injected into the class.

Extended Translator Capabilities

These are various methods that typically begin with method signature "supports" on the "ExecutionFactory" class. These methods need to be overridden to describe the execution capabilities of the Translator. Refer to Translator Capabilities for more on these methods.

Execution (and sub-interfaces)

Based on types of executions you are supporting, the following methods need to be overridden and need to provide implementations for these methods by extending respective interfaces.

  • createResultSetExecution- Override if you are doing read based operation that is returning a rows of results. For ex: select

  • createUpdateExecution- Override if you are doing write based operations. For ex:insert, update, delete

  • createProcedureExecution- Overide if you are doing procedure based operations. For ex; stored procedures. This works well for non-relational sources.
    You can choose to implement all the execution modes or just what you need. See more details on this below.

Metadata

Override and implement the method getMetadata(), if you want to expose the metadata about the source for use in Dynamic VDBs. This defines the tables, column names, procedures, parameters, etc. for use in the query engine. This method is not yet used by Designer tooling.

Logging

Teiid provides org.teiid.logging.LogManager class for logging purposes. Create a logging context and use the LogManager to log your messages. These will be automatically sent to the main Teiid logs. You can edit the "jboss-log4j.xml" inside "conf" directory of the JBoss AS's profile to add the custom context. Teiid uses Log4J as its underlying logging system.

Exceptions

If you need to bubble up any exception use org.teiid.translator.TranslatorException class.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 12:37:54 UTC, last content change 2013-03-14 16:27:14 UTC.